package com.txzt.gaea.common.exception;

import com.txzt.base.core.RtnInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 异常处理器
 * 
 * @Author scott
 * @Date 2019
 */
@RestControllerAdvice
@Slf4j
@Order(-1)
public class CustomExceptionHandler{

	/**
	 * 处理自定义异常
	 */
	@ExceptionHandler(CustomException.class)
	public RtnInfo<?> handleRRException(CustomException e){
		return RtnInfo.error(RtnInfo.SERVER_ERROR.getCode(),"操作失败，"+e.getMessage());
	}

	@ExceptionHandler(Exception.class)
	public RtnInfo<?> handleExcepti6on(Exception e){
		log.error(e.getMessage(), e);
		return RtnInfo.error(RtnInfo.SERVER_ERROR.getCode(),"操作失败，"+e.getMessage());
	}
}
